const util = require('../../utils/util');
const API = require('../../common/constant');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pserons: [],
    eventId: 0,
  },

  /**
   * 跳转到他人详情页面
   */
  toPersonInfo: function(e){
    console.log(e.currentTarget.id);
    let userId = wx.getStorageSync('userInfo').userId;
    if (e.currentTarget.id+'' === userId+''){
      wx.navigateTo({
        url: '../myInformation/myInformation?id=' + e.currentTarget.id
      })
    }else{
      wx.navigateTo({
        url: '../FanInfo/PersonInfo/PersonInfo?id=' + e.currentTarget.id
      })
    }
  },
  /**
   * 打电话
   */
  callPeople: function(e){
    console.log(e);
    let number = e.currentTarget.dataset.number;
    wx.makePhoneCall({
      phoneNumber: number,
      success: res => {
        console.log(res);
      },
      fail: err => {
        console.log(err);
      }
    })

  },

  /**
   * 退出饭约
   */
  exitEvent: function(){
    let id = this.data.eventId;
    if (this.data.status === 'false'){
      app.showUserInfo('很抱歉，已错过时间', 'none', 1500);
      return
    }
    wx.showModal({
      title: '退出活动',
      content: '是否退出活动',
      success: function (res) {
        if (res.confirm) {
          util.http({
            url: API.URL.REGISTRATION.EXIT_EVENTINFO,
            data: {
              idEventInfoId: id
            },
            success: res => {
              console.log(res);
              app.globalData.isNewIndex = true;
              app.globalData.isNewNearBy = true;
              wx.showToast({
                title: "您已经成功退出活动",
                icon: 'none',
                duration: 1500
              });
              setTimeout(() => {
                wx.navigateBack({})
              }, 1500);

            },
            fail: rej => {
              console.log(rej);
            }
          })
        }
      }
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    let status = options.status;
    this.setData({
      status: status
    })
    let that = this;
    util.http({
      url: API.URL.EVENT.FIGHTINGFRIENDS,
      data: {
        idEventInfoId: options.id,
        pageIndex: 1,
        pageSize: 10
      },
      success: res => {
        console.log(res.data.bussData);
        that.setData({
          pserons: res.data.bussData,
          eventId: options.id
        });
      },
      fail: rej => {
        console.log(rej);
      }
    })
  }
})